package com.demo.youxuanmall.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName("`order`")
// 防止循环引用导致序列化问题
@JsonIgnoreProperties(value = {"handler"})
public class Order {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    private String orderNo;
    
    private Long userId;
    
    private Long shippingId;
    
    private BigDecimal payment;
    
    private Integer paymentType;
    
    private BigDecimal postage;
    
    private Integer status; // 10:未付款, 20:已付款待发货, 30:已发货, 40:已完成, 50:已取消
    
    private LocalDateTime paymentTime;
    
    private LocalDateTime sendTime;
    
    private LocalDateTime endTime;
    
    private LocalDateTime closeTime;
    
    private LocalDateTime createTime;
    
    private LocalDateTime updateTime;
    
    @TableField(exist = false)
    private Address shippingAddress;
    
    @TableField(exist = false)
    private List<OrderItem> orderItems;
    
    @TableField(exist = false)
    private String statusDesc;
    
    public String getStatusDesc() {
        if (status == null) {
            return "";
        }
        switch (status) {
            case 10:
                return "未付款";
            case 20:
                return "已付款待发货";
            case 30:
                return "已发货";
            case 40:
                return "已完成";
            case 50:
                return "已取消";
            default:
                return "未知状态";
        }
    }
} 